package cj.web.portal.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cj.web.kly.domain.GroupDep;
import cj.web.kly.domain.GroupInfor;
import cj.web.kly.domain.GroupPeople;
import cj.web.kly.domain.SpecialistLabel;
import cj.web.portal.dao.GroupDepVoDAO;
import cj.web.portal.dao.GroupInforVoDAO;
import cj.web.portal.dao.GroupPeopleVoDAO;
import cj.web.portal.dao.SpecialistLabelVoDAO;

@Service
public class PeopleService {

	@Autowired
    private GroupPeopleVoDAO groupPeopleVoDAO;
	@Autowired
    private SpecialistLabelVoDAO specialistLabelDAO;
	@Autowired
    private GroupInforVoDAO groupInforVoDAO;
	@Autowired
    private GroupDepVoDAO groupDepVoDAO;
	
	/**
	 * 请求机构
	 * @param groupId
	 * @return
	 */
	public SpecialistLabel querySpecialistLabellis(int labelId){
		return specialistLabelDAO.queryById(labelId);
	}
	
	//学术
	public Map queryBySpecialistLabelPid(int pId){
		Map rep = new HashMap();
		SpecialistLabel specialistLabel = specialistLabelDAO.queryById(pId);
		List<Map> replis = new ArrayList<Map>();
		List<SpecialistLabel> specialistLabellis = specialistLabelDAO.queryBypId(pId);
		for(SpecialistLabel obj:specialistLabellis){
			Map l_rep = new HashMap();
			l_rep.put("labelId", obj.getId());
			l_rep.put("labelName", obj.getName());
			List<GroupPeople> groupPeoplelis = groupPeopleVoDAO.queryBylabelId(obj.getId());
			l_rep.put("peoplelis", groupPeoplelis);
			replis.add(l_rep);
		}
		rep.put("specialistLabel", specialistLabel);
		rep.put("replis", replis);
		return rep;
	}
	
	//团队详情
	public Map queryBySpecialistLabelDetailPid(int peopleId){
		Map rep = new HashMap();
		GroupPeople groupPeopleObj = groupPeopleVoDAO.queryById(peopleId);
		int labelId = groupPeopleObj.getLabelId();
		List<GroupPeople> groupPeoplelis = groupPeopleVoDAO.queryBylabelId(labelId);
		rep.put("labelId", labelId);
		rep.put("groupPeoplelis", groupPeoplelis);
		return rep;
	}
	
	/**
	 * 查询
	 * @param news
	 * @return groupPeoplelis;size
	 */
	public Map query(int depId,int start,int length){
		Map rep = new HashMap();
		List<GroupPeople> groupPeoplelis = groupPeopleVoDAO.querylis(depId, start, length);
		int size = groupPeopleVoDAO.querylisSize(depId);
		rep.put("groupPeoplelis", groupPeoplelis);
		rep.put("size", size);
		return rep;
    }
	
	//风采
	public List<GroupPeople> queryDetaillis(int depId){
		return groupPeopleVoDAO.queryDetaillis(depId);
	}
	
	public List<Map> queryCurrentDirectorlis(int groupId){
		List<Map> replis = new ArrayList<Map>();
		List<GroupDep> groupDeplis = groupDepVoDAO.queryNameByGroupId(groupId);
		for(GroupDep obj:groupDeplis){
			Map l_rep = new HashMap();
			List<GroupPeople> groupPeoplelis = groupPeopleVoDAO.queryDetaillis(obj.getId());
			l_rep.put("name", obj.getName());
			l_rep.put("groupPeoplelis", groupPeoplelis);
			
			replis.add(l_rep);
		}
		
		return replis;
	}
	
	//通过用户ID反查部门得出用户列表
	public Map queryByPeopleId(int id){
		Map rep = new HashMap();
		GroupPeople obj = groupPeopleVoDAO.queryById(id);
		List<GroupPeople> groupPeoplelis = groupPeopleVoDAO.queryBydepId(obj.getDepId());
		GroupInfor groupInfor = groupInforVoDAO.queryById(obj.getGroupId());
		GroupDep groupDep = groupDepVoDAO.queryById(obj.getDepId());
		
		rep.put("groupPeoplelis", groupPeoplelis);
		rep.put("groupInfor", groupInfor);
		rep.put("groupDep", groupDep);
		
		return rep;
	}
	
	//详情
	public GroupPeople queryById(int id){
		return groupPeopleVoDAO.queryById(id);
	}
}